// pages/shiyong/shiyong.js
let res = null
Page({

  /**
   * 页面的初始数据
   */
  data: {
    h1:0,
    h2:0,
    h3:0,
    h4:0,
    h5:0,
    h6:0,

    l1:0,
    l2:0,
    l3:0,
    l4:0,
    l5:0,
    l6:0,
    lastid: 0

      ,
    currentIndex: 0,

    red: 0,
    green: 0,
    s: '10:00',
    ABC: true
  },
  onShow: async function () {
    
    res = await wx.cloud.callFunction({
      name: 'shiyongget'
    })
    
    
    this.setData({
      mydata: res.result.res.data
    })
    //查询首页的内容
    console.log(res.result.res)
  },

  pagechange: function (e) {
    if ("touch" === e.detail.source) {
      let currentPageIndex = this.data.currentIndex
      currentPageIndex = (currentPageIndex + 1) % 3
      this.setData({
        currentIndex: currentPageIndex
      })
    }
  },
  titleClick: function (e) {
    let currentPageIndex = this.setData({
      //拿到当前索引并动态改变   
      currentIndex: e.currentTarget.dataset.idx
    })
  },


  dianshiqi() {
    var that = this
    var kaiguang = setInterval(function () {
      var a = that.hs_to_s(that.data.s)
      a = a - 1
      var c = that.s_to_hs(a)
      that.setData({
        s: c,
        kaiguang
      })
    }, 1000)
    this.setData({
      ABC: false
    })
  },
  disdinnshiqi() {
    clearInterval(this.data.kaiguang);
    this.setData({
      ABC: true,
    })
  },
  fuwei() {
    clearInterval(this.data.kaiguang);
    this.setData({
      ABC: true,
      s: '10:00'
    })
  },
  redfun: function (e) {
    var redfen = e.target.dataset.val
    var a = this.data.red
    var b = parseInt(a) + parseInt(redfen)
    this.setData({
      red: b,
    })
  },

  greenfun: function (e) {
    var redfen = e.target.dataset.val
    var a = this.data.green
    var b = parseInt(a) + parseInt(redfen)
    console.log(redfen)
    this.setData({
      green: b,
    })

  },
  jishi() {
    var a = this.hs_to_s(this.data.s)
    a = a - 1
    var c = this.s_to_hs(a)
    this.setData({
      s: c
    })
  },
  hs_to_s(s) {
    var a, b, c;
    a = s.toString().split(":")[0]
    b = s.toString().split(":")[1]
    c = parseInt(a) * 60 + parseInt(b)
    return c
  },
  s_to_hs(s) {
    //计算分钟
    //算法：将秒数除以60，然后下舍入，既得到分钟数
    var h;
    h = Math.floor(s / 60);
    //计算秒
    //算法：取得秒%60的余数，既得到秒数
    s = s % 60;
    //将变量转换为字符串
    h += '';
    s += '';
    //如果只有一位数，前面增加一个0
    h = (h.length == 1) ? '0' + h : h;
    s = (s.length == 1) ? '0' + s : s;

    return h + ':' + s;
  }
  ,
  tiaozhuan:function(){
    wx.navigateTo({
      url: '../shiyong/add/add?id=1',
    })
  }
  ,
  ondelete:function(event){
    var id = event.currentTarget.dataset.postid;
  
    console.log(id)
    wx.navigateTo({
      url: '../shiyong/delete/delete?id='+id,
    })
  }

,
//规则
hadd1:function(e){
  var that = this;
if(that.data.h1<5){
  this.setData({ h1: that.data.h1 + 1 });
}else{
  this.setData({ h1: that.data.h1 })
}
},
hadd2:function(e){
  var that = this;
if(that.data.h2<5){
  this.setData({ h2: that.data.h2 + 1 });
}else{
  this.setData({ h2: that.data.h2 })
}
},
hadd3:function(e){
  var that = this;
if(that.data.h3<5){
  this.setData({ h3: that.data.h3 + 1 });
}else{
  this.setData({ h3: that.data.h3 })
}
},
hadd4:function(e){
  var that = this;
if(that.data.h4<5){
  this.setData({ h4: that.data.h4 + 1 });
}else{
  this.setData({ h4: that.data.h4 })
}
},
hadd5:function(e){
  var that = this;
if(that.data.h5<5){
  this.setData({ h5: that.data.h5 + 1 });
}else{
  this.setData({ h5: that.data.h5 })
}
},
hadd6:function(e){
  var that = this;
if(that.data.h6<5){
  this.setData({ h6: that.data.h6 + 1 });
}else{
  this.setData({ h6: that.data.h6 })
}
},



ladd1:function(e){
  var that = this;
if(that.data.l1<5){
  this.setData({ l1: that.data.l1 + 1 });
}else{
  this.setData({ l1: that.data.l1 })
}
},
ladd2:function(e){
  var that = this;
if(that.data.l2<5){
  this.setData({ l2: that.data.l2 + 1 });
}else{
  this.setData({ l2: that.data.l2 })
}
},
ladd3:function(e){
  var that = this;
if(that.data.l3<5){
  this.setData({ l3: that.data.l3 + 1 });
}else{
  this.setData({ l3: that.data.l3 })
}
},
ladd4:function(e){
  var that = this;
if(that.data.l4<5){
  this.setData({ l4: that.data.l4 + 1 });
}else{
  this.setData({ l4: that.data.l4 })
}
},
ladd5:function(e){
  var that = this;
if(that.data.l5<5){
  this.setData({ l5: that.data.l5 + 1 });
}else{
  this.setData({ l5: that.data.l5 })
}
},
ladd6:function(e){
  var that = this;
if(that.data.l6<5){
  this.setData({ l6: that.data.l6 + 1 });
}else{
  this.setData({ l6: that.data.l6 })
}
},

})